﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Net;
using SoccerScore.Compact.Linq;
using System.Linq;
using System.Data.SqlServerCe;
using HtmlAgilityPack;
using System.Data.SqlClient;
using Soccer_Score_Forecast.BulkSql;
using SoccerScore.Compact.Linq.Review;

namespace Soccer_Score_Forecast
{
    public partial class Form1 : Form
    {        // Send plain text email with no attachment 
        private void send_predict_Click(object sender, EventArgs e)
        {



        }



        //过滤,grnn，3，0
        private void todayAnalysisReview(int filter, bool boolfilter)
        {
            bool checkall = checkEdit1.Checked;
            LoadDataMethod ldm = new LoadDataMethod();
            IEnumerable<Analysis_Review> tables;
            using (DataClassesMatchDataContext2 matches = new DataClassesMatchDataContext2(Conn.conn))
            {
                if (checkall)
                {
                    tables = matches.Analysis_Review
                        //.Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                                .Where(e => ldm.yesornorate.Contains(e.Match_type))
                        //.Where(e => e.bj_select == 1)
                                .OrderBy(e => e.Match_time);
                }
                else
                {
                    tables = matches.Analysis_Review
                            .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                            .Where(e => ldm.yesornorate.Contains(e.Match_type))
                        //.Where(e => e.bj_select == 1)
                            .OrderBy(e => e.Match_time);
                }

                //这里只过滤 让球的比赛，因此，filter==1


                if (filter == 1)
                {
                    if (boolfilter)
                        tables = matches.Analysis_Review
                                        .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                                        .Where(e => ldm.yesornorate.Contains(e.Match_type))
                                        .Where(e => filter_match.Contains(e.Match_type))
                                        .Where(e => e.bj_select == 1)
                                        .OrderBy(e => e.Match_time);
                    else
                        tables = matches.Analysis_Review
                                                .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                                                .Where(e => ldm.yesornorate.Contains(e.Match_type))
                            //.Where(e => filter_match.Contains(e.Match_type))
                                                .Where(e => e.bj_select == 1)
                                                .OrderBy(e => e.Match_time);

                    //todayMatchType = new List<string>();
                    todayMatchType = tables.Select(e => e.Match_type).Distinct().ToList();
                }

                if (filter == 2)
                {
                    if (boolfilter)
                        tables = matches.Analysis_Review
                                             .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                                             .Where(e => ldm.yesornorate.Contains(e.Match_type))
                                             .Where(e => filter_match_two.Contains(e.Match_type))
                                             .Where(e => e.bj_select == 2)
                                             .OrderBy(e => e.Match_time);
                    else
                        tables = matches.Analysis_Review
                                                          .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
                                                          .Where(e => ldm.yesornorate.Contains(e.Match_type))
                            //.Where(e => filter_match_two.Contains(e.Match_type))
                                                          .Where(e => e.bj_select == 2)
                                                          .OrderBy(e => e.Match_time);

                    //todayMatchType_two = new List<string>();
                    todayMatchType_two = tables.Select(e => e.Match_type).Distinct().ToList();

                }




            }
        }

        private string get_today_predict()
        {
            string predict = null;
            string onepre = null;
            //LoadDataMethod ldm = new LoadDataMethod();

            string pre = null;
            PredictAnalysisAfter paa = new PredictAnalysisAfter();

            var tables = paa.GetPredictOne_Today(overday);
                //.Where(e => ldm.yesornorate.Contains(e.Match_type));

            //using (DataClassesMatchDataContext2 matches = new DataClassesMatchDataContext2(Conn.conn))
            //{
            //    var tables = matches.Analysis_Review
            //        .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
            //        .Where(e => ldm.yesornorate.Contains(e.Match_type))
            //        .Where(e => e.bj_select == 1)
            //        .OrderBy(e => e.Match_time);
            foreach (var t in tables)
            {
                onepre = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", t.Match_time, t.Match_type,
                                            t.Home_team, t.Away_team, t.asia_odds,
                                            t.result_grnn, t.Result_goals, t.Result_wdl,
                                            t.full_home_goals.ToString() + "-" + t.full_away_goals.ToString(),
                                            t.Grnn_fit.Replace(" ", ""));

                if (filter_match != null)
                    if (filter_match.Contains(t.Match_type))
                        pre = "★" + t.Data_grnn;

                predict += string.Format("{0},{1},{2},{3},{4},{5},{6}\r\n",
                    pre, t.result_grnn, t.Data_grnn, t.Result_wdl, t.Data_wdl, onepre, t.Macau_predication);

                pre = null;

            }
            //}
            return predict;
        }

        private string get_today_predict_ab()
        {
            string predict = null;
            string onepre = null;
            //string twopre = null;
            //LoadDataMethod ldm = new LoadDataMethod();
            //getBjDangChang();

            PredictAnalysisAfter paa = new PredictAnalysisAfter();

            var tables = paa.GetPredictTwo_Today(overday);

            //using (DataClassesMatchDataContext2 matches = new DataClassesMatchDataContext2(Conn.conn))
            //{
            //    var tables = matches.Analysis_Review
            //        .Where(e => e.Match_time.Value > DateTime.Now.AddDays(overday))
            //        //.Where(e => e.Result_goals =="30")
            //        //.Where(e => e.Result_goals.Length == 3)
            //        //.Where(e => filter_match_two.Contains(e.Match_type))

            //        .Where(e => e.Data_wdl.Length != 3)  //过滤

            //        .Where(e => e.bj_select == 2)
            //        .OrderBy(e => e.Match_time);

            string pre = null;
            foreach (var t in tables)
            {
                onepre = string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                            t.Match_time, t.Match_type,
                                            t.Home_team, t.Away_team, t.asia_odds,
                    //t.result_grnn, t.Result_goals,
                                            t.full_home_goals.ToString() + "-" + t.full_away_goals.ToString(),
                                            t.Grnn_fit == null ? "" : t.Grnn_fit.Replace(" ", ""));
                if (filter_match_two != null)
                    if (filter_match_two.Contains(t.Match_type))
                        if (t.Data_wdl != null)
                        //if (t.Data_wdl.Length <= 2)
                        //    if (t.result_grnn != "1")  //算法调整
                        {
                            pre = "★" + t.Data_grnn;
                        }

                //if (t.Data_wdl == null)
                //{
                //    pre = "★";
                //    twopre = t.Data_wdl + t.composite_fit;
                //}



                predict += string.Format("{0},{1},{2},{3},{4}#{5},{6}\r\n",
                     pre, t.result_grnn, t.Data_grnn, t.Result_wdl, t.Data_wdl, onepre, t.Macau_predication);
                pre = null;
                //twopre = null;

            }
            //}

            return predict;
        }

        private void button27_Click(object sender, EventArgs e)
        {
            if (SendPredictEmail.SendEmail("jc777777@163.com", "jc777",
                 "jc777777@163.com", "jc777",
                 DateTime.Now.ToLongDateString(), get_today_predict_ouzhoubei(), false, null,
                 "smtp.163.com", "jc777777", "123qweasd"))
                //MessageBox.Show("Email sent successfully");
                toolStripStatusLabel1.Text = "Email sent successfully";
            else
                //MessageBox.Show("Failed to send email");
                toolStripStatusLabel1.Text = "Failed to send email";
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {


        }
        private string get_today_predict_ouzhoubei()
        {
            string predict = null;
            string onepre = null;
            //LoadDataMethod ldm = new LoadDataMethod();
            //getBjDangChang();
            using (DataClassesMatchDataContext2 matches = new DataClassesMatchDataContext2(Conn.conn))
            {
                var tables = matches.Analysis_Review
                            .Where(e => e.Match_type == "歐國盃")
                             .Where(e => e.Match_time > DateTime.Now.AddDays(-60))
                               .OrderBy(e => e.Match_time);

                string pre = null;
                foreach (var t in tables)
                {
                    onepre = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}",
                                                t.Match_time, t.Match_type,
                                                t.Home_team, t.Away_team, t.asia_odds,
                                                t.result_grnn, t.Result_goals, t.Result_wdl,
                                                t.full_home_goals.ToString() + "-" + t.full_away_goals.ToString(),
                                                t.Grnn_fit == null ? "" : t.Grnn_fit.Replace(" ", ""));

                    predict += string.Format("{0},{1},{2},{3}\r\n", t.result_grnn, pre, onepre, t.Macau_predication);
                    pre = null;

                }
            }

            return predict;
        }

    }
}
